home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue49 / Clinic / TimeZoneU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1999-05-23  |  3.1 KB  |  89 lines

  1. unit TimeZoneU;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TTimeZoneInfoForm = class(TForm)
  11.     lblCurrent: TLabel;
  12.     lblBias: TLabel;
  13.     lblStdBias: TLabel;
  14.     lblDayBias: TLabel;
  15.     lblDayToStd: TLabel;
  16.     lblStdToDay: TLabel;
  17.     procedure FormCreate(Sender: TObject);
  18.   private
  19.     { Private declarations }
  20.   public
  21.     { Public declarations }
  22.   end;
  23.  
  24. var
  25.   TimeZoneInfoForm: TTimeZoneInfoForm;
  26.  
  27. implementation
  28.  
  29. {$R *.DFM}
  30.  
  31. procedure TTimeZoneInfoForm.FormCreate(Sender: TObject);
  32. var
  33.   RetVal: DWord;
  34.   TZI: TTimeZoneInformation;
  35.   StdBias, DayBias: Integer;
  36.   StdName, DayName: String;
  37. const
  38.   OrdNums: array[1..5] of String = ('1st', '2nd', '3rd', '4th', 'last');
  39.   MinsPerDay = SecsPerDay / 60;
  40. begin
  41.   RetVal := GetTimeZoneInformation(TZI);
  42.   if RetVal = $FFFFFFFF then //API call failed
  43.     RaiseLastWin32Error;
  44.   if TZI.StandardName[0] = #0 then //No name information
  45.     StdName := 'standard time'
  46.   else
  47.     StdName := TZI.StandardName;
  48.   if TZI.DaylightName[0] = #0 then //No name information
  49.     DayName := 'daylight time'
  50.   else
  51.     DayName := TZI.DaylightName;
  52.   case RetVal of
  53.     TIME_ZONE_ID_UNKNOWN: lblCurrent.Caption := Format(lblCurrent.Caption, ['unknown time frame']);
  54.     TIME_ZONE_ID_STANDARD: lblCurrent.Caption := Format(lblCurrent.Caption, [StdName]);
  55.     TIME_ZONE_ID_DAYLIGHT: lblCurrent.Caption := Format(lblCurrent.Caption, [DayName]);
  56.   end;
  57.   lblBias.Caption := Format(lblBias.Caption, [TZI.Bias]);
  58.   StdBias := TZI.Bias + TZI.StandardBias;
  59.   lblStdBias.Caption := Format(lblStdBias.Caption, [StdBias, StdName]);
  60.   DayBias := TZI.Bias + TZI.DaylightBias;
  61.   lblDayBias.Caption := Format(lblDayBias.Caption, [DayBias, DayName]);
  62.   lblDayToStd.Caption := Format(lblDayToStd.Caption, [DayName, StdName]);
  63.   lblStdToDay.Caption := Format(lblStdToDay.Caption, [StdName, DayName]);
  64.   if TZI.StandardDate.wMonth = 0 then
  65.   begin
  66.     lblDayToStd.Caption := lblDayToStd.Caption + 'an unspecified point';
  67.     lblStdToDay.Caption := lblStdToDay.Caption + 'an unspecified point';
  68.     Exit;
  69.   end;
  70.   if TZI.StandardDate.wYear = 0 then //"Day of month" date
  71.     with TZI.StandardDate do
  72.       lblDayToStd.Caption := Format('%s%s on the %s %s of %s', [lblDayToStd.Caption,
  73.         TimeToStr(EncodeTime(wHour, wMinute, wSecond, wMilliseconds) + DayBias / MinsPerDay),
  74.         OrdNums[wDay], LongDayNames[wDayOfWeek + 1], LongMonthNames[wMonth + 1]])
  75.   else //Absolute date
  76.     lblDayToStd.Caption := lblDayToStd.Caption +
  77.       DateTimeToStr(SystemTimeToDateTime(TZI.StandardDate) + DayBias / MinsPerDay);
  78.   if TZI.DaylightDate.wYear = 0 then //"Day of month" date
  79.     with TZI.DaylightDate do
  80.       lblStdToDay.Caption := Format('%s%s on the %s %s of %s', [lblStdToDay.Caption,
  81.         TimeToStr(EncodeTime(wHour, wMinute, wSecond, wMilliseconds) + StdBias / MinsPerDay),
  82.         OrdNums[wDay], LongDayNames[wDayOfWeek + 1], LongMonthNames[wMonth + 1]])
  83.   else //Absolute date
  84.     lblStdToDay.Caption := lblStdToDay.Caption +
  85.       DateTimeToStr(SystemTimeToDateTime(TZI.DaylightDate) + StdBias / MinsPerDay)
  86. end;
  87.  
  88. end.
  89.